package servlet;

import dao.UserDAO1;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "userInfo", value = "/user/info")
public class UserInfoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 接受id
        String id = req.getParameter("id");
        //2. 调用dao.findById(id)
        UserDAO1 userDAO1 = new UserDAO1();
        User user = userDAO1.findById(id);
        req.setAttribute("user", user);  // 设置属性
        req.getRequestDispatcher("/user/Info.jsp").forward(req,resp);
        System.out.println(user);
    }
}
